package com.qidianit.mes.pro.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Bom;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pro.mapper.BomMapper;
import com.qidianit.mes.pro.mapper.MaterialCategoryMapper;
import com.qidianit.mes.pro.mapper.MaterialMapper;
import com.qidianit.mes.pro.mapper.UnitMapper;
import com.qidianit.mes.pro.service.BomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ Description:
 * @ Author:WuJingLei
 * @ Date: 2025/9/23 -17:07
 */
@Service
public class BomServiceImpl implements BomService {
    @Autowired
    private BomMapper bomMapper;
    @Autowired
    private MaterialMapper materialMapper;
    @Autowired
    private UnitMapper unitMapper;
    @Autowired
    private MaterialCategoryMapper categoryMapper;
    @Override
    public Result<PageInfo<Bom>> queryByParentId(Long id,int page,int size) {
        //分页
        PageHelper.startPage(page,size);
        //数据查询
        List<Bom> boms = bomMapper.queryByParentId(id);
        for (Bom bom : boms) {
            bom.setChildMaterial(materialMapper.queryById(bom.getChildMaterialId()));
            bom.getChildMaterial().setUnit(unitMapper.queryById(bom.getChildMaterial().getUnitId()));
            bom.getChildMaterial().setCategory(categoryMapper.queryByCategoryId(bom.getChildMaterial().getCategoryId()));
        }
        return Result.success(new PageInfo<>(boms));
    }
}
